Add explicit whitelist for Garmin waypoint names. Part 1 of 2.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 24 Jan 2005 00:13:46 +0000 (00:13 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 24 Jan 2005 00:13:46 +0000 (00:13 +0000)
gpsbabel/defs.h
gpsbabel/garmin.c
gpsbabel/mkshort.c

index 167d39d4e069e312bef0e0e5e52b711be4e7a289..7d8e89afc407516e7886cca01ec9492773448261 100644 (file)
@@ -306,6 +306,7 @@ void *MKSHORT_NEW_HANDLE(DEBUG_PARAMS);
 void mkshort_del_handle(void *h);
 void setshort_length(void *, int n);
 void setshort_badchars(void *, const char *);
+void setshort_goodchars(void *, const char *);
 void setshort_mustupper(void *, int n);
 void setshort_mustuniq(void *, int n);
 void setshort_whitespace_ok(void *, int n);
index dfaf25572e0826dd03f8efaa637be4dbca434aad..22c22df2d3ed073b0345f45c642f85b3e0e0b8d3 100644 (file)
@@ -138,6 +138,8 @@ rw_init(const char *fname)
        if (snwhiteopt)
                setshort_whitespace_ok(mkshort_handle, atoi(snwhiteopt));
 
+       /* Technically, even this is a little loose as spaces arent allowed */
+       setshort_goodchars(mkshort_handle, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
        setshort_mustupper(mkshort_handle, 1);
 
 }
@@ -438,6 +440,7 @@ waypoint_write(void)
                 * but rather a garmin "fixed length" buffer that's padded
                 * to the end with spaces.  So this is NOT (strlen+1).
                 */
+fprintf(stderr, "%s\n", ident);
                memcpy(way[i]->ident, ident, strlen(ident));
                if (global_opts.synthesize_shortnames) { 
                        xfree(ident);
index 3a9c787fa7d8b97df03e8a5ea918f2c341a5951c..b4b16212bc05ae81c47b31c20467f9648b664845 100644 (file)
@@ -43,6 +43,7 @@ typedef struct {
        int whitespaceok;
        unsigned int target_len;
        char *badchars;
+       char *goodchars;
        int must_uniq;
        queue namelist[PRIME];
        int depth[PRIME];
@@ -236,6 +237,13 @@ setshort_badchars(void *h, const char *s)
                hdl->badchars = xstrdup(s);
        }
 }
+void
+setshort_goodchars(void *h, const char *s)
+{
+       mkshort_handle *hdl = h;
+
+       hdl->goodchars = xstrdup(s);
+}
 
 void
 setshort_mustupper(void *h, int i)
@@ -334,6 +342,8 @@ mkshort(void *h, const char *istring)
        for (i=0;i<l;i++) {
                if (strchr(hdl->badchars, tstring[i]) || !isascii(tstring[i]))
                        continue;
+               if (hdl->goodchars && (!strchr(hdl->goodchars, tstring[i])))
+                       continue;
                *cp++ = tstring[i];
        }
        *cp = 0;